package com.yeban.base.day05;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/9/29
 *
 * 需求3：二维数组3X3，求其对角线元素之和
 */

public class TwoArrayTest03 {

    public static void main(String[] args) {

        int[][] arr = new int[5][5];
        //[3][3]{ {1,2,3}, {4,5,6}, {7,8,9}
        int sum1 = 0;
        int sum2 = 0;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {

                // 正对角线下标规律：行=列
                if(i == j) {
                    sum1 += arr[i][j];
                }

                // 负对角线下标规律：行 + 列 = arr.length - 1
                if(i == j) {
                    sum2 += arr[i][j];
                }
            }

        }
    }
}
